package cn.guizhou001.demo.controller;

import cn.guizhou001.demo.model.Hello;
import cn.guizhou001.demo.service.HelloService;
import cn.guizhou001.demo.util.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author fengli
 * @Description: TODO
 * @date 2018年06月28日 14:36
 */
// 推荐用RestController 不用用Controller
@RestController
@RequestMapping("/hello")
public class HelloController {

    /**
     * 日志工具类
     */
    private static Logger LOGGER = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private HelloService helloService;

    /**
     * 查询数据
     *
     * @return
     */
    @GetMapping("list")
    public Map<String, Object> list() {
        List<Hello> datalist = helloService.list(1, 10);

        return MessageUtils.modelMap(datalist);
    }

    @PostMapping("add")
    public Map<String, Object> add(Hello hello) {

        // 记录日志
        LOGGER.info("hello:" + hello);

        return MessageUtils.modelMap("添加成功");
    }
}